<?php
/**
 * Nuwani PHP IRC Bot Framework
 * Copyright (c) 2006-2010 The Nuwani Project
 *
 * Nuwani is a framework for IRC Bots built using PHP. Nuwani speeds up bot 
 * development by handling basic tasks as connection- and bot management, timers
 * and module managing. Features for your bot can easily be added by creating
 * your own modules, which will receive callbacks from the framework.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @copyright Copyright (c) 2006-2011 The Nuwani Project
 * @author Peter Beverloo <peter@lvp-media.com>
 * @author Dik Grapendaal <dik.grapendaal@gmail.com>
 * @see http://nuwani.googlecode.com
 */

//namespace Nuwani;

/**
 * Uno Nuwani Module
 * 
 * @copyright Copyright (c) 2011 The Nuwani Project, http://nuwani.googlecode.com/
 * @author Dik Grapendaal <dik.grapendaal@gmail.com>
 * @version $Id: UnoDeckCard.php 141 2011-07-23 21:47:01Z dik.grapendaal $
 * @package Modules
 */

class UnoDeckCard extends UnoCard
{
        /**
         * Locations used when the card is not in the possession of a player.
         */
        
        const   LOCATION_DECK           = -1;
        const   LOCATION_TOP_CARD       = -2;
        
        /**
         * The unique ID for this card.
         * 
         * @var integer
         */

        private $mId;
        
        /**
         * Indicates the current location of this card, e.g. in the deck, open
         * as the top card, or in the hand of a player. A negative value
         * corresponds with the constants in this class, any positive value is
         * the player ID this card is currently assigned to.
         * 
         * @var integer
         */
        
        private $mLocation;
        
        /**
         * The constructor prepares the UnoDeckCard object. It requires an extra
         * parameter, $engine, that's needed to register this card with the 
         * running UnoEngine.
         * 
         * @param UnoEngine $engine The running UnoEngine.
         * @param int $color The color of this card.
         * @param int $number The number of this card.
         * @param int $location The initial location of this card.
         */
        
        public function __construct (UnoEngine $engine, $color, $number, $location = self :: LOCATION_DECK)
        {
                if (!$engine -> registerCard ($this, $location, $color, $number))
                {
                        throw new Exception (UnoStrings :: INVALID_CARD);
                }
                
                $this -> mLocation = $location;
                
                parent :: __construct ($color, $number);
        }
        
        /**
         * Returns the unique ID of this card.
         *
         * @return int
         */
        
        public function getId ()
        {
                return $this -> mId;
        }
        
        /**
         * Returns the current location of this card. In case of a positive
         * value, the value indicates the player ID of the person holding the
         * card. In case of a negative value, -1 indicates the deck, -2 
         * indicates this card is the top card.
         * 
         * @return int
         */
        
        public function getLocation ()
        {
                return $this -> mLocation;
        }
        
        /**
         * Sets the location of this card. For more information, see the 
         * getLocation() method.
         * 
         * @param int $location The location to set for this card.
         */
        
        public function setLocation ($location)
        {
                $this -> mLocation = $location;
        }
        
        /**
         * Returns the amount of points this card is worth.
         * 
         * @return integer
         */
        
        public function getCardValue ()
        {
                if ($this -> getNumber () >= UnoEngine :: CARD_0
                 && $this -> getNumber () <= UnoEngine :: CARD_9)
                {
                        return $this -> getNumber () - 1;
                }
                else if ($this -> isWildcard ())
                {
                        return 50;
                }
                else
                {
                        return 20;
                }
        }
        
        /**
         * Creates a discardable copy of this UnoDeckCard.
         * 
         * @return UnoCard
         */
        
        public function toUnoCard ()
        {
                return new UnoCard
                (
                        $this -> getColor (),
                        $this -> getNumber (),
                        $this -> getNextColor ()
                );
        }
}